package com.example.kjn.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.AppCompatEditText;
import android.support.v7.widget.AppCompatTextView;
import android.view.View;

import com.example.kjn.myapplication.per.UserPer;
import com.example.kjn.myapplication.view.UserView;

public class MainActivity extends AppCompatActivity implements UserView {

    private UserPer userPer;
    private AppCompatEditText editText;
    private AppCompatEditText editText2;
    private AppCompatEditText editText3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        userPer = new UserPer(this);
        editText = (AppCompatEditText) findViewById(R.id.appCompatEditText);
        editText2 = (AppCompatEditText) findViewById(R.id.appCompatEditText2);
        editText3 = (AppCompatEditText) findViewById(R.id.appCompatEditText3);

    }

    public void save(View view) {
        userPer.save();
    }

    public void load(View view) {
        userPer.load();
    }

    @Override
    public int getId() {

        return DataValidationUtils.getInt(editText.getText().toString().trim());
    }

    @Override
    public String getName() {
        return DataValidationUtils.getString(editText2.getText().toString().trim());
    }

    @Override
    public String getPSW() {
        return DataValidationUtils.getString(editText3.getText().toString().trim());
    }

    @Override
    public void setName(String name) {
        editText2.setText(name);
    }

    @Override
    public void setPSW(String psw) {
        editText3.setText(psw);
    }

}
